<template>
  <h1>当前求和：{{ sum }}</h1>
  <h2>姓名：{{ person.name }}</h2>
  <h2>年龄：{{ person.age }}</h2>
  <h2>工资：{{ person.job.j1.salary }}</h2>

  <button @click="sum ++">+1</button>
  <button @click="person.name += '~'">改姓名</button>
  <button @click="person.age++">改年龄</button>
  <button @click="person.job.j1.salary++">涨工资</button>
</template>
  
  <script>
import { reactive, computed, ref, watch,watchEffect } from "vue";
export default {
  name: "App",
  components: {},

  setup(props, context) {
    let sum=ref(0)
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 20,
        },
      },
    });
  
    // watch(
    //   person,
    //   (newValue, oldValue) => {
    //     console.log(newValue, oldValue);
    //   },
    //   {
    //     immediate: true,
    //     deep: true,
    //   }
    // );
    // 
    watchEffect(()=>{
      console.log('watchEffect执行啦');
      // 反应  发送网络请求？
      // 用到谁 监视谁   写在该函数中
      // 当所用到的数据变化时 重新执行回调函数
      const x1=sum.value
      const x2=person.job.j1.salary

    })
    
   

    return { person ,sum};
  },
};
</script>
  
  <style>
</style>
  